<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body ng-app="myApp" ng-controller="myCtrl">

</body>
<script src="node_modules/angular/angular.js"></script>
<script>
    var app=angular.module('myApp',[]);
    app.controller('myCtrl',function ($q) {
        //通过$q服务来使用promise方法
        function getData() {
            var defer=$q.defer();
            var status=false;
            if(status){
                defer.resolve({text:'这是成功的数据'})
            }else{
                defer.reject({text:'失败的数据'});
            }
            return defer.promise;
        }
        getData()
            .then(function (data) {
                console.log('这是从resolve中获取到的数据');
                console.log(data);
            },function (data) {
                console.log('这是从reject中获取到的数据');
                console.log(data);
            })
    });

</script>
</html>